package scheduledExecutorService;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/****
 * 使用线程池的方式来实现定时
 *
 */
public class ScheduledExecutorServiceTest {
   
	public static void main(String[] args) {
		Runnable runnable =new Runnable() {
			
			@Override
			public void run() {
				System.out.println("Hello !!");
			}
		};
		
		ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
		// 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
		scheduledExecutorService.scheduleAtFixedRate(runnable, 1, 1, TimeUnit.SECONDS);
	}
}
